<template>
 <div class="icons-list">
    <swiper v-if="showSwiper">
      <swiper-slide v-for="(page,index) of pages" :key="index">
        <div class="iconBtn" v-for="item of page" :key="item.id">
          <div class="icon-item">
            <img :src=item.img>
            <p class="icon-name">{{item.keyword}}</p>
          </div>
        </div>
      </swiper-slide>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  props: {
    list: Array
  },
  computed: {
    pages () {
      const pages = []
      this.list.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item)
      })
      return pages
    },
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
.icons-list
  background: #ffffff
  width: 100%
  height: 0
  padding-bottom: 50%
  overflow: hidden
  .iconBtn
    position: relative
    float: left
    width: 25%
    height: 0
    padding-bottom: 25%
    text-align center
    .icon-item
      position: absolute
      padding: .2rem
      width: 100%
      top: 50%
      left: 50%
      transform: translate(-50%,-50%)
      img
        width: 55%
      .icon-name
        height: .44rem
        line-height: .44rem
        overflow: hidden
        white-space: nowrap
        text-overflow: ellipsis
        color: #212121
</style>
